package com.tanhua.sso.controller;

import com.tanhua.sso.service.UserInfoService;
import com.tanhua.sso.utils.sendmsgutils;
import com.tanhua.sso.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.zookeeper.OpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("user")
@Slf4j
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;
    private Result result;
    @PostMapping("loginReginfo")
    public ResponseEntity<Object> saveUserInfo(@RequestBody Map<String, String> parm,
                                               @RequestHeader("Authorization") String token) {
        try {
             result = userInfoService.saveUserInfo(parm, token);
            if(result==null){
             return  ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);
    }
    @PostMapping("loginReginfo/head")
    public ResponseEntity<Object> saveUserlogo(@RequestParam(value = "headPhoto")MultipartFile file,
                                               @RequestHeader("Authorization") String token){

        try {
            Result result=userInfoService.saveUserlogo(file,token);
            if(result==null){
                return  ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);
    }
}

